<?php
##############################################
#
#   商铺
# @ Time : 2017-1-8 - 下午9:20:27
# @ Author : JiangYongWei <1085562810@qq.com>
# @ Encoding : UTF-8 language : PHP
#
##############################################


namespace Admin\Model;
use Admin\Model\AdminBaseModel;

class PrizeRecordModel extends AdminBaseModel{
    /**
     * 获取所有抽奖用户
     */
    public function getUser($user_name,$mobile,$type,$starttime,$endtime){
        //var_dump($type);var_dump($mobile);
        if($mobile)
        {
            $map['mt_prize_record.mobile'] = $mobile;
        }
        if($user_name)
        {
            $map['mt_prize_record.user_name'] = array('like','%'.$user_name.'%');
        }
        if($type == 0)
        {
            $map['mt_prize_record.prize_type'] = array('in',array(1,2));
        }else
        {
            $map['mt_prize_record.prize_type'] = $type;
        }



        if ($starttime && $endtime)
            $map['time'] = array('between',array($starttime,$endtime));
        elseif ($starttime)
            $map['time'] = array('egt',$starttime);
        elseif ($endtime)
            $map['time'] = array('elt',$endtime);

        $count = $this -> where($map) -> count();// 查询满足要求的总记录数
        $Page = new \Think\Page($count, 20);
        $show = $Page -> show();

        $result = $this
            ->field('mt_prize_record.*,mt_prize.prize_name')->where($map)
            ->join('LEFT JOIN mt_prize ON mt_prize.p_id = mt_prize_record.prize_id')
            ->order('record_id desc')
            ->limit($Page->firstRow.','.$Page->listRows)
            -> select();

        $resultExcel = $this
            ->field('mt_prize_record.*,mt_prize.prize_name')->where($map)
            ->join('LEFT JOIN mt_prize ON mt_prize.p_id = mt_prize_record.prize_id')
            ->order('record_id desc')
            -> select();
        return array($result, $show,$resultExcel);
    }
    /**
     * 删除
     */
    public function deleteUser($p_id){
        return $this -> where("record_id = $p_id") -> delete();
    }

    /**
     *删除选中
     * @param $idArr
     * @return bool
     * @Date 201703
     * @Author Linsenquan
     */
    public function deleteAllPriRe($idArr)
    {
        foreach($idArr['id'] as $vo)
        {
            $this->where(array('record_id'=>$vo))->delete();
        }
        return true;
    }
}